package org.github.rayson517.easyplatform.common.web.util;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;


/**
 * <p>Title: JsonUtlis</p>
 * <p>Description: Json 转化工具</p>
 * @author rayson517
 * @date 2018-03-29 10:35
 * @version 1.0
 */
public class JsonUtlis {
	
	/** 将obj对象转化成为json对象，并设置时间转化格式
	 * @param obj 
	 * @param format 时间格式
	 * @return
	 */
	public static String objToJsonStr(Object obj, String format){
		
		if (obj == null || StringUtils.isEmpty(format)) {
			throw new NullPointerException("参数");
		}
	
		//自定义序列化格式  
		JSON.DEFFAULT_DATE_FORMAT = format;
		return  JSON.toJSONString(obj, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
	}

}
